/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.area_info_his.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.mvc.support.RedirectAttributes;

import com.thinkgem.jeesite.common.config.Global;
import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.web.BaseController;
import com.thinkgem.jeesite.common.utils.StringUtils;
import com.thinkgem.jeesite.modules.area_info_his.entity.AreaInfoHis;
import com.thinkgem.jeesite.modules.area_info_his.service.AreaInfoHisService;

/**
 * 车位历史信息Controller
 * @author admin
 * @version 2019-04-15
 */
@Controller
@RequestMapping(value = "${adminPath}/area_info_his/areaInfoHis")
public class AreaInfoHisController extends BaseController {

	@Autowired
	private AreaInfoHisService areaInfoHisService;
	
	@ModelAttribute
	public AreaInfoHis get(@RequestParam(required=false) String id) {
		AreaInfoHis entity = null;
		if (StringUtils.isNotBlank(id)){
			entity = areaInfoHisService.get(id);
		}
		if (entity == null){
			entity = new AreaInfoHis();
		}
		return entity;
	}
	
	@RequiresPermissions("area_info_his:areaInfoHis:view")
	@RequestMapping(value = {"list", ""})
	public String list(AreaInfoHis areaInfoHis, HttpServletRequest request, HttpServletResponse response, Model model) {
		Page<AreaInfoHis> page = areaInfoHisService.findPage(new Page<AreaInfoHis>(request, response), areaInfoHis); 
		model.addAttribute("page", page);
		return "modules/area_info_his/areaInfoHisList";
	}

	@RequiresPermissions("area_info_his:areaInfoHis:view")
	@RequestMapping(value = "form")
	public String form(AreaInfoHis areaInfoHis, Model model) {
		model.addAttribute("areaInfoHis", areaInfoHis);
		return "modules/area_info_his/areaInfoHisForm";
	}

	@RequiresPermissions("area_info_his:areaInfoHis:edit")
	@RequestMapping(value = "save")
	public String save(AreaInfoHis areaInfoHis, Model model, RedirectAttributes redirectAttributes) {
		if (!beanValidator(model, areaInfoHis)){
			return form(areaInfoHis, model);
		}
		areaInfoHisService.save(areaInfoHis);
		addMessage(redirectAttributes, "保存车位历史信息成功");
		return "redirect:"+Global.getAdminPath()+"/area_info_his/areaInfoHis/?repage";
	}
	
	@RequiresPermissions("area_info_his:areaInfoHis:edit")
	@RequestMapping(value = "delete")
	public String delete(AreaInfoHis areaInfoHis, RedirectAttributes redirectAttributes) {
		areaInfoHisService.delete(areaInfoHis);
		addMessage(redirectAttributes, "删除车位历史信息成功");
		return "redirect:"+Global.getAdminPath()+"/area_info_his/areaInfoHis/?repage";
	}

}